﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp.Domain.Entities.Auditing;

namespace Linker.TaskCenter.Services
{
    [Table("Services")]
    public class ServiceEntity : FullAuditedEntity<Guid>
    {
        public ServiceEntity(Guid id)
        {
            Id = id;
            Status = ServiceHealthyEnum.Unknown;
            MaxRetry = 1;
        }

        /// <summary>
        ///     服务名称
        /// </summary>
        [Required]
        [StringLength(128)]
        public virtual string ServerName { get; set; }

        /// <summary>
        ///     服务方法
        /// </summary>
        [StringLength(128)]
        public virtual string Method { get; set; }

        /// <summary>
        ///     服务地址
        /// </summary>
        [StringLength(128)]
        [Url]
        public virtual string Url { get; set; }

        /// <summary>
        ///     请求参数
        /// </summary>
        [MaxLength]
        public virtual string Parameter { get; set; }

        /// <summary>
        ///     响应参数
        /// </summary>
        [MaxLength]
        public virtual string Response { get; set; }

        /// <summary>
        ///     描述
        /// </summary>
        [StringLength(255)]
        public virtual string Description { get; set; }

        /// <summary>
        ///     最大重试次数
        /// </summary>
        [Required]
        public virtual int MaxRetry { get; set; }

        /// <summary>
        ///     健康检查
        /// </summary>
        [StringLength(255)]
        public string HealthCheckUrl { get; set; }

        /// <summary>
        ///     状态
        /// </summary>
        public ServiceHealthyEnum Status { get; set; }

        /// <summary>
        ///     最后健康检查时间
        /// </summary>
        public DateTime? LastHealthyCheckTime { get; set; }
    }
}